package com.sztle.admodule.resp;

import java.util.HashMap;
import java.util.Map;

public class ServiceHelper {

    private static Map<String, Object> sServiceMap = new HashMap();

    public static <T> T getService(Class<T> tClass) {
        if (sServiceMap.containsKey(tClass.getSimpleName())) {
            return (T) sServiceMap.get(tClass.getSimpleName());
        }

        T service = RetrofitManager.getInstance().create(tClass);
        sServiceMap.put(tClass.getSimpleName(), service);
        return service;
    }

    public static <T> T getService(Class<T> tClass, String baseUrl) {
        if (sServiceMap.containsKey(tClass.getSimpleName())) {
            return (T) sServiceMap.get(tClass.getSimpleName());
        }

        T service = RetrofitManager.getInstance(baseUrl).create(tClass);
        sServiceMap.put(tClass.getSimpleName(), service);
        return service;
    }

}
